$appinfo.logid//登录用户名;
$appinfo.ocode//登录组织编号;
$appinfo.orgID//登录组织phid;
$appinfo.userID//登录用户phid;
$appinfo.username//登录用户姓名;

var mstform = Ext.getCmp('p_form0000700124_m');
var dgrid = Ext.getCmp('p_form0000700124_dgrid');
var dstore = dgrid.store;
var Toolbar = Ext.getCmp('toolbar');
var pc = mstform.getItem('pc')
var deptid = mstform.getItem('deptid')
var ycleid = mstform.getItem('cycleid')

mstform.getItem('pc').getValue();//获取表头控件值
mstform.getItem('textcol_1').userSetReadOnly(true);//true-只读   false-不只读
mstform.getItem('textcol_1').userSetMustInput(true);// true-必输   false-不必输
mstform.getItem('textcol_1').setVisible(true);//true-可见   false-隐藏
mstform.getItem('textcol_1').userSetMask();//	表头控件设为显示掩码
mstform.getItem('pc1').setValue(AAA); //AAA为对象
mstform.getItem('pc1').setValue('大楼开工项目'); //字符串等

BatchBindCombox([cycleid])
console.log(Ext.Date.format(new Date(), 'Y-m-d H:i:s'))

var today = mstform.getItem('bill_dt').getValue();
var year = today.getFullYear();// 获取年份
var month = today.getMonth() + 1;
console.log("当前年份是：" + year);// 输出年份
console.log("当前月份是：" + month);

setTimeout(function () {
}, 1000)

function AllReady() {

}
function allReadyEdit() {

}
function beforeSaveEdit() {//保存前

}
function beforeUnVerifyEdit() {//取消审核前

}
function beforeUnVerifyList() {//列表取消审核前

}

// if (otype == $Otype.ADD || otype == $Otype.EDIT || otype == $Otype.COPY) {

// }

if (otype == 'add' || otype == 'copy' || otype == 'edit' || otype == 'view') {

}

function isEmpty(value) {
    return value === null || value === undefined || value.trim() === '' || value === '0';
}


//检测是否加载完成
mstform.on('dataready', function () {
    console.log('Data ready event triggered');
});

dgrid.getStore().on('load', function (store, records) {
    console.log('Data loaded into grid');
});

mstform.on('afterrender', function () {
    console.log('Form rendered');
});

mstform.getItem('pc').addListener('helpselected', function () { //表头帮助窗口选择后触发

});
mstform.getItem('pc').addListener('itemchanged', function () {//焦点离开后触发

});
mstform.getItem('pc').addListener('change', function () {//值发生变化后立即触发

});
mstform.getItem('cntno').on('beforetriggerclick', function (eOp, ignoreBeforeEvent) {//通用帮助过滤

})

//主表通用帮助过滤
mstform.getItem('cntno').on('beforetriggerclick', function (eOp, ignoreBeforeEvent) {
    var pc = mstform.getItem('pc').getValue();
    if (Ext.isEmpty(pc)) {
        Ext.Msg.alert('提示', '请先选择项目！');
        mstform.getItem('pc').focus();
        return false;
    } else {
        mstform.getItem('cntno').setOutFilter({
            phid_pc: pc //phid_pc 字段是通用帮助中的字段
        });
    }
});
//明细表通用帮助过滤
dgrid.addListener('edit', function (editor, e) {     //监听单据体编辑状态，edit-编辑；add-增行；cellclick-点击
    if (e.field == 'u_esjfl') {                       //监听字段变化
        var record = e.record;
        var data = dgrid.getSelectionModel().getSelection();   //获取当前选中行
        var u_esjfl = data[0].get('u_esjfl');     //获取当前选中行某个字段值
        dgrid.getColumn('u_yssjfl_name').getEditor().on('beforetriggerclick', function (eOp, ignoreBeforeEvent) {
            dgrid.getColumn('u_yssjfl_name').getEditor().setOutFilter({ 'phid_parent': u_esjfl })//过滤另一个字段的选择项
        });
    }
})
// 表体通用帮助过滤 表体帮助过滤
dgrid.getColumn('u_cbs_name').getEditor().addListener('beforetriggerclick', function () {

    var data = dgrid.getSelectionModel().getSelection();//获取表体当前选中行
    var pc = mstform.getItem('u_gcxm').getValue();
    // dgrid.getColumn('u_cbs_name').getEditor().setOutFilter({
    //     c_no: $appinfo.userID
    // });
    if (pc != '' || pc != null || data.length > 0) {
        dgrid.getColumn('u_cbs_name').getEditor().setClientSqlFilter('pcid =' + pc);
        //dgrid.('u_cbs_name').getEditor().setClientSqlFilter('bd_cbs.pcid =' + pc);
        //dgrid.('u_cbs_name').getEditor().setClientSqlFilter('pcid in (142211118000091,142211118000092)');
    }

});




/////////////////////////////////////////////////////////////////////////////////////////求和
{
    //单据状态为新增,修改或复制
    if (otype == 'add' || otype == 'copy' || otype == 'edit' || otype == 'view') {
        dstore.on('add', function (store, records, index, eOpts) {
            SetTotal();
        });

        //表体删行事件触发
        dstore.on('remove', function (store, records, index, eOpts) {
            SetTotal();
        });
        //表体编辑触发
        dgrid.addListener('edit', function (editor, e) {
            var record = e.record;
            if (e.originalValue == e.value) { return; }
            record.set('u_fpje', Ext.Number.from(record.get('u_hyghje'), 0) - Ext.Number.from(record.get('u_sdje'), 0));
            SetTotal();
        });
    }
    //计算结算信息中的逻辑
    function SetTotal() {
        var sum_amt_1 = 0;//金额
        // 遍历 dstore 中的每个项
        dstore.each(function (item) {
            // 转换为数字
            let amt_1 = Ext.Number.from(item.get('u_hyghje'), 0);
            sum_amt_1 += amt_1;
        });
        u_hyghze.setValue(sum_amt_1)

    }
    const fieldsToWatch = ['numericcol_1', 'numericcol_2', 'numericcol_3', 'numericcol_4', 'numericcol_5', 'numericcol_6'];
    function updateAmtValue() {
        let total = 0;
        for (const field of fieldsToWatch) {
            total += Ext.Number.from(mstform.getItem(field).getValue(), 0);
        }
        mstform.getItem('u_amtall').setValue(total);
    }
    if (otype == $Otype.ADD || otype == $Otype.EDIT || otype == $Otype.COPY) {
        for (const field of fieldsToWatch) {
            mstform.getItem(field).addListener('change', updateAmtValue);
        }
    }

    function getSum(mstform, dstore) {//表体计算 修改后  循环计算前暂停渲染，结束后再开启
        Ext.suspendLayouts();
        var sum = 0;
        for (var i = 0; i < dstore.getCount(); i++) {
            var tax_rate = dstore.getAt(i).get('tax_rate')    //税率
            var qty = dstore.getAt(i).get('qty')    //数量
            var unit_price = dstore.getAt(i).get('unit_price')    //含税单价
            var prc = unit_price / (1 + tax_rate)    //不含税单价
            var tax_price = unit_price * qty   //价税合计
            var amt = tax_price / (1 + tax_rate)    //不含税金额
            var tax_amount = tax_price - amt    //税额
            dstore.getAt(i).set('prc', prc);
            dstore.getAt(i).set('tax_price', tax_price);
            dstore.getAt(i).set('amt', amt);
            dstore.getAt(i).set('tax_amount', tax_amount);
            sum += Ext.Number.from(dstore.getAt(i).get('tax_price'), 0);
            mstform.getItem('tax_price').setValue(sum);
        }
        Ext.resumeLayouts();
    }


}

callServer('proj', [{ 'phid': pc }], function (res) {
    data[0].set('textcol_1', res.record[0].province + res.record[0].city);
    data[0].set('datetimecol_1', res.record[0].start_date);
    data[0].set('datetimecol_2', res.record[0].end_date);
});

//自动带入申请人部门
execServer('addCntGetDept', { 'creator': creator.getValue() }, function (res) {
    if (res.data.length > 0) {
        var a = res.data[0];
        user_bm.setValue(a.bm);
        BatchBindCombox([user_bm])
    }
});

if (otype == $Otype.ADD || otype == $Otype.EDIT || otype == $Otype.COPY) {
    execServer('GetTjzq', { 'BillDt': mstform.getItem('bill_dt').getValue() }, function (res) {
        if (res.count > 0) {
            cycleid.setValue(res.data[0].phid);
            BatchBindCombox([cycleid])
            console.log(cycleid.getValue())
        }
    });
}
if (otype == $Otype.ADD || otype == $Otype.EDIT || otype == $Otype.COPY) {
    mstform.getItem('cycleid').addListener('helpselected', function () { //表头帮助窗口选择后触发
        execServer('GetTjzq_dt', { 'phid': mstform.getItem('cycleid').getValue() }, function (res) {
            if (res.count > 0) {
                today = res.data[0].edt
                console.log(today)
            }
        });
    });
}
if (otype == $Otype.ADD || otype == $Otype.EDIT || otype == $Otype.COPY) {
    dstore.on('datachanged', async function (dstore, eOpts) {
        var uyear = today.getFullYear();
        var umonth = today.getMonth() + 1;
        console.log("当前年份是：" + year);
        console.log("当前月份是：" + month);
        const records = dstore.getRange();
        for (const record of records) {
            try {
                const pb90Response = await new Promise((resolve, reject) => {
                    execServer('getPb90_01', { 'uyear': uyear, 'userhelp': record.get('userhelp_3') }, function (res) {
                        resolve(res);
                    });
                });
                if (pb90Response.data.length > 0) {
                    record.set('u_yearly_target', pb90Response.data[0].amt_y);
                }
            } catch (error) {
                console.error(error);
            }
        }
    });
}





dgrid.addListener('edit', function (editor, e) {
    dgrid.getColumn('userhelp_3').getEditor().addListener('helpselected', function () {
        const data = dgrid.getSelectionModel().getSelection();//获取当前选中行
        execServer('getPb90_01', { 'deptid': deptid.getValue(), 'nian': 2023, 'userhelp': data[0].get('userhelp_3') }, function (res) {
            if (res.data.length > 0) {
                data[0].set('u_yearly_target', res.data[0].amt_y);//割算
            }
        });
    });
});










//根据项目经营模式设置CBS必填
if (otype == $Otype.ADD || otype == $Otype.EDIT || otype == $Otype.VIEW || otype == $Otype.COPY) {
    execServer('Get_pt_jyms', { 'phid': PhidPc.getValue() }, function (res) {
        if (res.data.length > 0) {
            jyms = (res.data[0].user_jymshi)
            if (jyms == "190211112000027") {
                dgrid.setMustInputCol('PhidCbs_EXName', false);// 通用帮助加_name true-必输   false-不必输
            }
        }
    });
}





//表体字段根据值的不同,取值来源不同
if (record.get('ItemResource') == 'p_form0000700083_d') {
    var phid_supp_ent = record.get('PhidSuppEnt')//声明变量供应商
    execServer('GetPform54', { 'phid': phid_supp_ent, 'pc': pc.getValue() }, function (res) {
        if (res.data.length > 0) {
            record.set('user_confinalamt', res.data[0].amt);//结算
        }
    });
    execServer('GetPform83', { 'phid': phid_supp_ent, 'pc': pc.getValue() }, function (res) {
        if (res.data.length > 0) {
            record.set('user_cnt_projbal', res.data[0].amt);//按合同约定累计应付款额
            record.set('user_ljyf', res.data[0].amt1);//累计已付款
        }
    });
    record.set('user_yfbl', Ext.Number.from(record.get('user_cnt_projbal'), 0) / Ext.Number.from(record.get('user_confinalamt'), 0));//按合同约定应付款比例
    record.set('user_fkbl', Ext.Number.from(record.get('user_ljyf'), 0) / Ext.Number.from(record.get('user_cnt_projbal'), 0));//累计已付款比例
    record.set('user_qfk', Ext.Number.from(record.get('user_cnt_projbal'), 0) - Ext.Number.from(record.get('user_ljyf'), 0));//按合同约定欠付款
}







//表体增行事件
dstore.on('add', function (store, records, index, eOpts) {//表体增行事件触发
    var records = dgrid.getStore().getRange(index, index)[0];
    records.set('Feetype', "0069"); ////-------->费用类型 编码
    records.set('FeeName', "差旅费"); ///-------->费用类型 名称
    records.set('PhidFeetype_EXName', "差旅费"); ///-------->费用类型 名称
    records.set('PhidFeetype', '517181106000071'); ///------>费用类型phid
    for (i = 0; i < records.length; i++) {
        records[i].set('Edt', '2022-01-06 13:18:55');
    }
});//事件结束

var mstform = Ext.getCmp('p_form0000700149_m');
var dgrid = Ext.getCmp('p_form0000700149_dgrid');
var Toolbar = Ext.getCmp('toolbar');
var dstore = dgrid.store;
Toolbar.insert(5, { itemId: "demb", text: "增行", width: this.itemWidth, iconCls: "icon-New" });   //指定位置插入按钮
Toolbar.get('demb').on('click', function () {
    var help = Ext.create('Ext.ng.MultiRichHelp', {
        valueField: 'phid',   //代码列
        displayField: 'c_name',  //名称列
        helpid: 'dalx',         //获取帮助ID
        ORMMode: false,
        outFilter: {
            'pid': mstform.getItem('userhelp_1').getValue()
        } //判断条件，因为该通用帮助的两张表中均有phid列，因此需声明取哪张表的phid列，若列唯一可以直接写为phid(无需引号)	 
    });
    help.showHelp();
    help.on('helpselected', function (obj) {
        var arr = new Array();
        for (i = 0; i < obj.data.length; i++) {
            arr.push({
                userhelp_1: obj.data[i].data.phid,
                userhelp_1_name: obj.data[i].data.c_name,
            })
        }
        // dgrid.getStore().insert(dgrid.getStore().getCount(), arr);
        var selectedRecords = dgrid.getSelectionModel().getSelection();
        if (selectedRecords.length > 0) {
            var selectedRecord = selectedRecords[0];
            var selectedIndex = dgrid.getStore().indexOf(selectedRecord);
            dgrid.getStore().insert(selectedIndex + 1, arr);
        } else {
            dgrid.getStore().insert(dgrid.getStore().getCount(), arr);
        }

    });
})

function allReadyEdit() {
    //根据通用帮助批量新增明细
    const mstform = Ext.getCmp('p_form0000700101_m');
    const dgrid = Ext.getCmp('p_form0000700101_dgrid');
    const dstore = dgrid.store;

    if (otype == $Otype.ADD) {
        var help = Ext.create('Ext.ng.MultiRichHelp', {
            valueField: 'phid',   //代码列
            displayField: 'c_name',  //名称列
            helpid: 'gzbgzlmx',         //获取帮助ID
            ORMMode: false,
        });
        help.showHelp();
        help.on('helpselected', function (obj) {
            // Use forEach for array iteration
            const recordsToAdd = [];
            obj.data.forEach(item => {
                recordsToAdd.push({
                    // u_lb: item.data.c_descript,  // Assuming c_descript is defined somewhere
                    userhelp_1: item.data.phid,
                    userhelp_1_name: item.data.c_name,
                });
            });
            dstore.insert(dstore.getCount(), recordsToAdd);
        });
    }
}


//字段选择后自动带入
var pc = mstform.getItem('pc');
var org_id = mstform.getItem('org_id');
var org_id1 = mstform.getItem('org_id1');
var amt_1 = mstform.getItem('amt_1');
function handleHelpSelected() {
    if (pc.getValue() !== '' && pc.getValue() !== '0' && pc.getValue() !== null) {
        execServer("GetPtInfo", { phid: pc.getValue() }, function (res) {
            if (res.data.length > 0) {
                BatchBindCombox([org_id.setValue(res.data[0].phid_company)]);//建设单位ID
                BatchBindCombox([org_id1.setValue(res.data[0].phid_sg_org)]);//施工单位ID
                amt_1.setValue(res.data[0].approx_contract_fc);//项目金额
            }
        });
    }
}
if (otype == $Otype.ADD || otype == $Otype.EDIT || otype == $Otype.COPY) {
    setTimeout(function () {
        handleHelpSelected();
    }, 1000)//延迟执行
    pc.addListener("helpselected", function () {
        handleHelpSelected();
    });
}


function allReadyEdit() {
    const mstform = Ext.getCmp('p_form0000700089_m');
    const dgrid = Ext.getCmp('p_form0000700089_dgrid');
    const dstore = dgrid.store;


}


function AllReady() {
    const mstform = Ext.getCmp('CntProjBal1');
    const dgrid = Ext.getCmp('CntProjBalD1');
    const dstore = dgrid.store;
    var ShouldAmtVatFc = mstform.getItem('ShouldAmtVatFc');//累计应收，已提报问题单，临时写脚本控制，=表体单据金额BillAmtVatFcs
    dgrid.addListener('edit', function (editor, e) {     //监听单据体编辑状态，edit-编辑；add-增行；cellclick-点击
        const record = e.record;
        const data = dgrid.getSelectionModel().getSelection(); //获取当前选中行
        if (e.originalValue == e.value) {//判断原值与新值是否相同
            return;
        }
        if (e.field == 'PayApplyAmtVatFc') {
            record.set('Zfbl', Ext.Number.from(record.get('PayApplyAmtVatFc'), 0) / Ext.Number.from(record.get('BillAmtVatFc'), 0)); //计算amt值
        };
    })
}
function beforeSaveEdit() {
    const mstform = Ext.getCmp('CntProjBal1');
    const dgrid = Ext.getCmp('CntProjBalD1');
    const dstore = dgrid.store;
    var ShouldAmtVatFc = mstform.getItem('ShouldAmtVatFc');//累计应收，已提报问题单，临时写脚本控制，=表体单据金额BillAmtVatFcs
    var sum = 0
    for (i = 0; i < dstore.getCount(); i++) {
        sum += Ext.Number.from(dstore.getAt(i).get('BillAmtVatFc'), 0);

    }
    ShouldAmtVatFc.setValue(sum);
    return true;
}



function AllReady() {
    const mstform = Ext.getCmp('CntProjBal1');
    const dgrid = Ext.getCmp('CntProjBalD1');
    const dstore = dgrid.store;
    if (otype == $Otype.ADD || otype == $Otype.EDIT || otype == $Otype.COPY) {
        dstore.on('add', function (store, records, index, eOpts) {
            Ext.each(records, function (record) {
                const payApplyAmtVatFc = Ext.Number.from(record.get('PayApplyAmtVatFc'), 0);
                const billAmtVatFc = Ext.Number.from(record.get('BillAmtVatFc'), 0);
                record.set('Zfbl', payApplyAmtVatFc / billAmtVatFc);//支付比例，临时写脚本计算
            });
        });
        dgrid.addListener('edit', function (editor, e) {
            const record = e.record;
            if (e.originalValue === e.value) {
                return;
            }
            if (e.field === 'PayApplyAmtVatFc' && record.get('BillAmtVatFc') !== undefined) {
                record.set('Zfbl', Ext.Number.from(record.get('PayApplyAmtVatFc'), 0) / Ext.Number.from(record.get('BillAmtVatFc'), 0));//支付比例，临时写脚本计算
            }
        });
    }

}

function allReadyEdit() {
    var mstform = Ext.getCmp('p_form0000700062_m');
    var pc = mstform.getItem('pc')
    var jhnd = mstform.getItem('jhnd')//计划年度
    var dgrid = Ext.getCmp('p_form0000700062_dgrid');//产值
    var d0store = dgrid.store;
    var d1grid = Ext.getCmp('p_form0000700062_d1grid');//收入
    var d1store = d1grid.store;
    var d2grid = Ext.getCmp('p_form0000700062_d2grid');//回款
    var d2store = d2grid.store;
    var d3grid = Ext.getCmp('p_form0000700062_d3grid');//付款
    var d3store = d3grid.store;
    let allowAddRow0 = true;
    let allowAddRow1 = true;
    let allowAddRow2 = true;
    let allowAddRow3 = true;
    //增行是取值本年累计和开工累计,2023年一个逻辑，2024年及之后一个逻辑；
    function handleAddEvent(store, allowAddRowFlag, fields1, fields2) {
        store.on('add', function (store, records, index, eOpts) {
            // 检查 jhnd 是否有值
            if (!jhnd.getValue()) {
                Ext.Msg.alert('提示', '计划年度不能为空');
                store.remove(records);
                return;
            }
            // 检查是否允许新增行，每一个页签只允许新增一行
            if (allowAddRowFlag) {
                // 检查是否已经存在行
                if (store.getCount() > 1) {
                    Ext.Msg.alert('提示', '表体只能存在一行');
                    store.remove(records);
                    return;
                }
                Ext.each(records, function (record) {
                    execServer('GetPtJysj', { 'phid': pc.getValue() }, function (res) {
                        if (res.data.length > 0) {
                            fields1.forEach(field => {
                                record.set(field[0], res.data[0][field[1]]);
                            });
                        }
                    });
                    execServer('GetPtJysjUyear', { 'phid': pc.getValue(), 'uyear': jhnd.getValue() }, function (res) {
                        if (res.data.length > 0) {
                            fields2.forEach(field => {
                                record.set(field[0], res.data[0][field[1]]);
                            });
                        }
                    });
                });
                // 设置标志为false，防止再次新增行
                allowAddRowFlag = false;
            } else {
                // 如果不允许新增行，则移除新增的记录
                store.remove(records);
            }
        });
    }
    // 对每个页签调用处理函数，传入相应的参数
    handleAddEvent(d0store, allowAddRow0, [['amt', 'cz']], [['amt_2', 'cz']]);
    handleAddEvent(d1store, allowAddRow1, [['amt', 'sr']], [['amt_9', 'sr']]);
    handleAddEvent(d2store, allowAddRow2, [['amt', 'hk']], [['amt_9', 'hk']]);
    handleAddEvent(d3store, allowAddRow3, [['amt', 'fk']], [['amt_9', 'fk']]);
    // 如果有其他页签，可以按照类似的方式调用 handleAddEvent
}


function GetPtInfo(field, u_fi_org, gfi_ocode) {
    if (field.getValue() !== '' && field.getValue() !== '0' && field.getValue() !== null) {
        execServer('GetPtInfo', { 'phid_pc': field.getValue() }, function (res) {
            if (res.data.length > 0) {
                BatchBindCombox([u_fi_org.setValue(res.data[0].phid_fi_ocode)]);
                BatchBindCombox([gfi_ocode.setValue(res.data[0].phid_fi_ocode)]);
            }
        });
    }
}
{
    //SELECT phid,phid_company,phid_sg_org,approx_contract_fc,user_bzsm,user_cjfs,user_cwzz,user_czlx,user_EASxmbm,user_gtjf,user_lxr,user_lxyj,user_mblrl1,user_ssbm,user_sszg,user_xmfz,user_zjlx,user_zjly,user_zzlb FROM project_table AS pt where phid=@phid
    function updateFormField(container, fieldName, value) {//检查自定义字段是否存在，不存在则跳过
        var field = container.getItem(fieldName);
        if (field) {
            field.setValue(value);
            // 如果需要批量绑定下拉框，则在这里调用 BatchBindCombox 函数
            BatchBindCombox([field]);
        }
    }
    function updateFormFields(container, data) {//需要更新的字段
        if (data.length > 0) {
            updateFormField(container, 'user_bzsm', data[0].user_bzsm);//备注说明U
            updateFormField(container, 'user_cjfs', data[0].user_cjfs);//承接方式U
            updateFormField(container, 'user_cwzz', data[0].user_cwzz);//财务组织U
            updateFormField(container, 'user_czlx', data[0].user_czlx);//建设模式U
            updateFormField(container, 'user_EASxmbm', data[0].user_EASxmbm);//EAS项目编码U
            updateFormField(container, 'user_gtjf', data[0].user_gtjf);//共同甲方U
            updateFormField(container, 'user_lxr', data[0].user_lxr);//立项人U
            updateFormField(container, 'user_lxyj', data[0].user_lxyj);//立项依据U
            updateFormField(container, 'user_mblrl1', data[0].user_mblrl1);//目标利润率U
            updateFormField(container, 'user_ssbm', data[0].user_ssbm);//实施部门U
            updateFormField(container, 'user_sszg', data[0].user_sszg);//实施主管U
            updateFormField(container, 'user_xmfz', data[0].user_xmfz);//项目分组U
            updateFormField(container, 'user_zjlx', data[0].user_zjlx);//资金类型U
            updateFormField(container, 'user_zjly', data[0].user_zjly);//资金来源U
            updateFormField(container, 'user_zzlb', data[0].user_zzlb);//组织类别U
        }
    }
    function getPtInfo(container) {//获取功能扩展及字段来源
        var opt = container.getItem("PhIdOri");
        if (opt.getValue() !== '' && opt.getValue() !== '0' && opt.getValue() !== null) {
            execServer('GetPtInfo', { 'phid': opt.getValue() }, function (res) {
                updateFormFields(container, res.data);
            });
        }
    }
    function AllReady() {
        var adjustmstCmpCfg = Ext.getCmp('adjustmstCmpCfg');//工程建设
        var formProjectTableProjInve = Ext.getCmp('formProjectTableProjInve');//工程投资
        var formProjectTableBusiMana = Ext.getCmp('formProjectTableBusiMana');//企业管理
        if (otype == $Otype.ADD || otype == $Otype.EDIT || otype == $Otype.COPY) {
            if (adjustmstCmpCfg) {//如果是工程建设，则执行
                getPtInfo(adjustmstCmpCfg);
            }
            if (formProjectTableProjInve) {//如果是投资项目则执行
                getPtInfo(formProjectTableProjInve);
            }
            if (formProjectTableBusiMana) {//如果是企业管理，则执行
                getPtInfo(formProjectTableBusiMana);
            }
        }
    }
}
dstore.on('add', async function (store, records, index, eOpts) {
    if (!u_nian.getValue() || !deptid.getValue()) {
        Ext.Msg.alert('提示', '预算年度和预算部门不能为空');
        store.remove(records);
        return;
    }

    for (const record of records) {
        const res90 = await fetchData('getPb90_01', { 'deptid': deptid.getValue(), 'uyear': u_nian.getValue() - 1, 'userhelp': record.get('u_yssjfl') });
        const res132 = await fetchData('GetPb132_01', { 'deptid': deptid.getValue(), 'uyear': u_nian.getValue() - 1, 'ef3_phid': record.get('u_yssjfl') });

        if (res90.data && res90.data.length > 0) {
            record.set('u_snys', res90.data[0].amt_y);
        }
        if (res132.data && res132.data.length > 0) {
            record.set('u_snlj', res132.data[0].amt_y);
        }
    }
});

// Assuming execServer returns a Promise
function fetchData(serverMethod, params) {
    return new Promise((resolve, reject) => {
        execServer(serverMethod, params, resolve);
    });
}

function userSetMustInput(A, B) {
    if (A.getValue() == '295210621000001') {
        B.userSetMustInput(true);// true-必输   false-不必输
    } else {
        B.userSetMustInput(false);// true-必输   false-不必输
    }
}

function AllReady() {
    const mstform = Ext.getCmp('CntM5');
    var CntType = mstform.getItem("CntType");//合同类型
    var user_aqzr = mstform.getItem("user_aqzr");//安全责任人
    if (otype == $Otype.ADD || otype == $Otype.EDIT || otype == $Otype.COPY) {
        userSetMustInput(CntType, user_aqzr);
        CntType.addListener('helpselected', function () { //表头帮助窗口选择后触发
            userSetMustInput(CntType, user_aqzr);
        });
    }
}

function GetTJZQ(mstform, bill_dt, cycleid) {//获取统计周期
    var bill_dt = mstform.getItem("bill_dt");
    var cycleid = mstform.getItem("cycleid");
    execServer('GetTJZQ', { 'BillDt': bill_dt.getValue() }, function (res) {
        if (res.count > 0) {
            cycleid.setValue(res.data[0].phid);
            BatchBindCombox([cycleid])
        }
    });
}
function GetPtCwzz(mstform, pc, u_cwzz) {//获取项目财务组织
    var pc = mstform.getItem('pc');
    var u_cwzz = mstform.getItem("u_cwzz");
    if (pc.getValue() !== '' && pc.getValue() !== '0' && pc.getValue() !== null) {
        execServer('GetPtCwzz', { 'phid_pc': pc.getValue() }, function (res) {
            if (res.count > 0) {
                u_cwzz.setValue(res.data[0].user_cwzz);
                BatchBindCombox([u_cwzz])
            }
        });
    }
}

function allReadyEdit() {//控件设置
    const mstform = Ext.getCmp('p_form0000700142_m');
    const dgrid = Ext.getCmp('p_form0000700142_dgrid');
    const dstore = dgrid.store;


    if (otype == $Otype.ADD || otype == $Otype.EDIT || otype == $Otype.COPY) {
        GetTJZQ(mstform, bill_dt, cycleid);
        GetPtCwzz(mstform, pc, u_cwzz);
        mstform.getItem('pc').addListener('helpselected', function () { //表头帮助窗口选择后触发
            GetPtCwzz(mstform, pc, u_cwzz);
        });

        dgrid.addListener('edit', function (editor, e) {
            getSum(mstform, dstore);

        })

    }
}


function allReadyEdit() {//控件设置
    const mstform = Ext.getCmp('p_form0000700095_m');
    const dgrid = Ext.getCmp('p_form0000700095_dgrid');
    var userhelp_1 = mstform.getItem("userhelp_1");//主文件ID
    var textcol_2 = mstform.getItem("textcol_2");//规格型号
    var msunit = mstform.getItem("msunit");

    if (otype == $Otype.ADD || otype == $Otype.EDIT || otype == $Otype.COPY) {
        mstform.getItem('userhelp_1').addListener('helpselected', function () { //表头帮助窗口选择后触发
            execServer('GetItemdata', { 'phid': userhelp_1.getValue() }, function (res) {
                if (res.count > 0) {
                    textcol_2.setValue(res.data[0].spec);
                    msunit.setValue(res.data[0].phid_msunit);
                    BatchBindCombox([msunit])
                }
            });
        });
    }
}
function allReadyEdit() {
    var mstform = Ext.getCmp('p_form0000700063_m');
    var dgrid = Ext.getCmp('p_form0000700063_dgrid');
    var pc = mstform.getItem('pc')
    var dstore = dgrid.store;
    { //tab页的显示与隐藏
        //隐藏tab页 
        var tabPanel = Ext.getCmp('tabPanel');
        var tab1 = tabPanel.items.items[0];
        tabPanel.remove(tab1); //方法1
        tabPanel.hide(tab1); //方法2
        //显示tab页
        tabPanel.show(tab1); //方法2
    }
}


var dgrid = Ext.getCmp('p_form0000700032_d1grid');
var dstore = dgrid.store;
{ //tab页的显示与隐藏
    //隐藏tab页 
    if (otype == $Otype.ADD || otype == $Otype.EDIT || otype == $Otype.COPY || otype == $Otype.VIEW) {
        var tabPanel = Ext.getCmp('tabPanel');
        var tab1 = tabPanel.items.items[1];
        tabPanel.remove(tab1); //方法1
        // tabPanel.hide(tab1); //方法2
        //显示tab页
        // tabPanel.show(tab1); //方法2
    }

}







//系统表单单据编辑页面初始化
function AllReady() {
    var mstform = Ext.getCmp('ProjResM');
    var dgrid = Ext.getCmp('ProjResD');
    var dstore = dgrid.store;


    $appinfo.logid//登录用户名;
    $appinfo.ocode//登录组织编号;
    $appinfo.orgID//登录组织phid;
    $appinfo.userID//登录用户phid;
    $appinfo.username//登录用户姓名;
JSON.parse



    BatchBindCombox([cycleid])


    CntProjBalList1.hide()//hide()为隐藏设置，可通用于字段、容器    //	隐藏容器	

    Ext.Msg.alert('提示', '取数失败');//弹出提示框


    //单据状态为新增,修改或查看或复制
    if (otype == $Otype.ADD || otype == $Otype.EDIT || otype == $Otype.VIEW || otype == $Otype.COPY) {
        setTimeout(function () {
        }, 1000)
    }
}


function allReadyEdit() {
    var mstform = Ext.getCmp('p_form0000700063_m');
    var dgrid = Ext.getCmp('p_form0000700063_dgrid');
    var pc = mstform.getItem('pc')
    var dstore = dgrid.store;
    { //tab页的显示与隐藏
        //隐藏tab页 
        var tabPanel = Ext.getCmp('tabPanel');
        var tab1 = tabPanel.items.items[0];
        tabPanel.remove(tab1); //方法1
        tabPanel.hide(tab1); //方法2
        //显示tab页
        tabPanel.show(tab1); //方法2
    }
}

var today = mstform.getItem('bill_dt').getValue();
// 获取年份
var year = today.getFullYear();
var month = today.getMonth() + 1;
// 输出年份
console.log("当前年份是：" + year);
console.log("当前月份是：" + month);











//自动带入申请人部门
execServer('addCntGetDept', { 'creator': creator.getValue() }, function (res) {
    if (res.data.length > 0) {
        var a = res.data[0];
        user_bm.setValue(a.bm);
        BatchBindCombox([user_bm])
    }
});

if (otype == $Otype.ADD || otype == $Otype.EDIT || otype == $Otype.COPY) {
    execServer('GetTjzq', { 'BillDt': mstform.getItem('bill_dt').getValue() }, function (res) {
        if (res.count > 0) {
            cycleid.setValue(res.data[0].phid);
            BatchBindCombox([cycleid])
            console.log(cycleid.getValue())
        }
    });
}
if (otype == $Otype.ADD || otype == $Otype.EDIT || otype == $Otype.COPY) {
    mstform.getItem('cycleid').addListener('helpselected', function () { //表头帮助窗口选择后触发
        execServer('GetTjzq_dt', { 'phid': mstform.getItem('cycleid').getValue() }, function (res) {
            if (res.count > 0) {
                today = res.data[0].edt
                console.log(today)
            }
        });
    });
}
if (otype == $Otype.ADD || otype == $Otype.EDIT || otype == $Otype.COPY) {
    dstore.on('datachanged', async function (dstore, eOpts) {
        var uyear = today.getFullYear();
        var umonth = today.getMonth() + 1;
        console.log("当前年份是：" + year);
        console.log("当前月份是：" + month);
        const records = dstore.getRange();
        for (const record of records) {
            try {
                const pb90Response = await new Promise((resolve, reject) => {
                    execServer('getPb90_01', { 'uyear': uyear, 'userhelp': record.get('userhelp_3') }, function (res) {
                        resolve(res);
                    });
                });
                if (pb90Response.data.length > 0) {
                    record.set('u_yearly_target', pb90Response.data[0].amt_y);
                }
            } catch (error) {
                console.error(error);
            }
        }
    });
}





dgrid.addListener('edit', function (editor, e) {
    dgrid.getColumn('userhelp_3').getEditor().addListener('helpselected', function () {
        const data = dgrid.getSelectionModel().getSelection();//获取当前选中行
        execServer('getPb90_01', { 'deptid': deptid.getValue(), 'nian': 2023, 'userhelp': data[0].get('userhelp_3') }, function (res) {
            if (res.data.length > 0) {
                data[0].set('u_yearly_target', res.data[0].amt_y);//割算
            }
        });
    });
});










//根据项目经营模式设置CBS必填
if (otype == $Otype.ADD || otype == $Otype.EDIT || otype == $Otype.VIEW || otype == $Otype.COPY) {
    execServer('Get_pt_jyms', { 'phid': PhidPc.getValue() }, function (res) {
        if (res.data.length > 0) {
            jyms = (res.data[0].user_jymshi)
            if (jyms == "190211112000027") {
                dgrid.setMustInputCol('PhidCbs_EXName', false);// 通用帮助加_name true-必输   false-不必输
            }
        }
    });
}






//表体字段根据值的不同,取值来源不同
if (record.get('ItemResource') == 'p_form0000700083_d') {
    var phid_supp_ent = record.get('PhidSuppEnt')//声明变量供应商
    execServer('GetPform54', { 'phid': phid_supp_ent, 'pc': pc.getValue() }, function (res) {
        if (res.data.length > 0) {
            record.set('user_confinalamt', res.data[0].amt);//结算
        }
    });
    execServer('GetPform83', { 'phid': phid_supp_ent, 'pc': pc.getValue() }, function (res) {
        if (res.data.length > 0) {
            record.set('user_cnt_projbal', res.data[0].amt);//按合同约定累计应付款额
            record.set('user_ljyf', res.data[0].amt1);//累计已付款
        }
    });
    record.set('user_yfbl', Ext.Number.from(record.get('user_cnt_projbal'), 0) / Ext.Number.from(record.get('user_confinalamt'), 0));//按合同约定应付款比例
    record.set('user_fkbl', Ext.Number.from(record.get('user_ljyf'), 0) / Ext.Number.from(record.get('user_cnt_projbal'), 0));//累计已付款比例
    record.set('user_qfk', Ext.Number.from(record.get('user_cnt_projbal'), 0) - Ext.Number.from(record.get('user_ljyf'), 0));//按合同约定欠付款
}







//表体增行事件
dstore.on('add', function (store, records, index, eOpts) {//表体增行事件触发
    var records = dgrid.getStore().getRange(index, index)[0];
    records.set('Feetype', "0069"); ////-------->费用类型 编码
    records.set('FeeName', "差旅费"); ///-------->费用类型 名称
    records.set('PhidFeetype_EXName', "差旅费"); ///-------->费用类型 名称
    records.set('PhidFeetype', '517181106000071'); ///------>费用类型phid
    for (i = 0; i < records.length; i++) {
        records[i].set('Edt', '2022-01-06 13:18:55');
    }
});//事件结束



function allReadyEdit() {
    //根据通用帮助批量新增明细
    const mstform = Ext.getCmp('p_form0000700101_m');
    const dgrid = Ext.getCmp('p_form0000700101_dgrid');
    const dstore = dgrid.store;

    if (otype == $Otype.ADD) {
        var help = Ext.create('Ext.ng.MultiRichHelp', {
            valueField: 'phid',   //代码列
            displayField: 'c_name',  //名称列
            helpid: 'gzbgzlmx',         //获取帮助ID
            ORMMode: false,
        });
        help.showHelp();
        help.on('helpselected', function (obj) {
            // Use forEach for array iteration
            const recordsToAdd = [];
            obj.data.forEach(item => {
                recordsToAdd.push({
                    // u_lb: item.data.c_descript,  // Assuming c_descript is defined somewhere
                    userhelp_1: item.data.phid,
                    userhelp_1_name: item.data.c_name,
                });
            });
            dstore.insert(dstore.getCount(), recordsToAdd);
        });
    }
}


//字段选择后自动带入
var pc = mstform.getItem('pc');
var org_id = mstform.getItem('org_id');
var org_id1 = mstform.getItem('org_id1');
var amt_1 = mstform.getItem('amt_1');
function handleHelpSelected() {
    if (pc.getValue() !== '' && pc.getValue() !== '0' && pc.getValue() !== null) {
        execServer("GetPtInfo", { phid: pc.getValue() }, function (res) {
            if (res.data.length > 0) {
                BatchBindCombox([org_id.setValue(res.data[0].phid_company)]);//建设单位ID
                BatchBindCombox([org_id1.setValue(res.data[0].phid_sg_org)]);//施工单位ID
                amt_1.setValue(res.data[0].approx_contract_fc);//项目金额
            }
        });
    }
}
if (otype == $Otype.ADD || otype == $Otype.EDIT || otype == $Otype.COPY) {
    setTimeout(function () {
        handleHelpSelected();
    }, 1000)//延迟执行
    pc.addListener("helpselected", function () {
        handleHelpSelected();
    });
}


function allReadyEdit() {
    const mstform = Ext.getCmp('p_form0000700089_m');
    const dgrid = Ext.getCmp('p_form0000700089_dgrid');
    const dstore = dgrid.store;


}


function AllReady() {
    const mstform = Ext.getCmp('CntProjBal1');
    const dgrid = Ext.getCmp('CntProjBalD1');
    const dstore = dgrid.store;
    var ShouldAmtVatFc = mstform.getItem('ShouldAmtVatFc');//累计应收，已提报问题单，临时写脚本控制，=表体单据金额BillAmtVatFcs
    dgrid.addListener('edit', function (editor, e) {     //监听单据体编辑状态，edit-编辑；add-增行；cellclick-点击
        const record = e.record;
        const data = dgrid.getSelectionModel().getSelection(); //获取当前选中行
        if (e.originalValue == e.value) {//判断原值与新值是否相同
            return;
        }
        if (e.field == 'PayApplyAmtVatFc') {
            record.set('Zfbl', Ext.Number.from(record.get('PayApplyAmtVatFc'), 0) / Ext.Number.from(record.get('BillAmtVatFc'), 0)); //计算amt值
        };
    })
}
function beforeSaveEdit() {
    const mstform = Ext.getCmp('CntProjBal1');
    const dgrid = Ext.getCmp('CntProjBalD1');
    const dstore = dgrid.store;
    var ShouldAmtVatFc = mstform.getItem('ShouldAmtVatFc');//累计应收，已提报问题单，临时写脚本控制，=表体单据金额BillAmtVatFcs
    var sum = 0
    for (i = 0; i < dstore.getCount(); i++) {
        sum += Ext.Number.from(dstore.getAt(i).get('BillAmtVatFc'), 0);

    }
    ShouldAmtVatFc.setValue(sum);
    return true;
}



function AllReady() {
    const mstform = Ext.getCmp('CntProjBal1');
    const dgrid = Ext.getCmp('CntProjBalD1');
    const dstore = dgrid.store;
    if (otype == $Otype.ADD || otype == $Otype.EDIT || otype == $Otype.COPY) {
        dstore.on('add', function (store, records, index, eOpts) {
            Ext.each(records, function (record) {
                const payApplyAmtVatFc = Ext.Number.from(record.get('PayApplyAmtVatFc'), 0);
                const billAmtVatFc = Ext.Number.from(record.get('BillAmtVatFc'), 0);
                record.set('Zfbl', payApplyAmtVatFc / billAmtVatFc);//支付比例，临时写脚本计算
            });
        });
        dgrid.addListener('edit', function (editor, e) {
            const record = e.record;
            if (e.originalValue === e.value) {
                return;
            }
            if (e.field === 'PayApplyAmtVatFc' && record.get('BillAmtVatFc') !== undefined) {
                record.set('Zfbl', Ext.Number.from(record.get('PayApplyAmtVatFc'), 0) / Ext.Number.from(record.get('BillAmtVatFc'), 0));//支付比例，临时写脚本计算
            }
        });
    }

}

function allReadyEdit() {
    var mstform = Ext.getCmp('p_form0000700062_m');
    var pc = mstform.getItem('pc')
    var jhnd = mstform.getItem('jhnd')//计划年度
    var dgrid = Ext.getCmp('p_form0000700062_dgrid');//产值
    var d0store = dgrid.store;
    var d1grid = Ext.getCmp('p_form0000700062_d1grid');//收入
    var d1store = d1grid.store;
    var d2grid = Ext.getCmp('p_form0000700062_d2grid');//回款
    var d2store = d2grid.store;
    var d3grid = Ext.getCmp('p_form0000700062_d3grid');//付款
    var d3store = d3grid.store;
    let allowAddRow0 = true;
    let allowAddRow1 = true;
    let allowAddRow2 = true;
    let allowAddRow3 = true;
    //增行是取值本年累计和开工累计,2023年一个逻辑，2024年及之后一个逻辑；
    function handleAddEvent(store, allowAddRowFlag, fields1, fields2) {
        store.on('add', function (store, records, index, eOpts) {
            // 检查 jhnd 是否有值
            if (!jhnd.getValue()) {
                Ext.Msg.alert('提示', '计划年度不能为空');
                store.remove(records);
                return;
            }
            // 检查是否允许新增行，每一个页签只允许新增一行
            if (allowAddRowFlag) {
                // 检查是否已经存在行
                if (store.getCount() > 1) {
                    Ext.Msg.alert('提示', '表体只能存在一行');
                    store.remove(records);
                    return;
                }
                Ext.each(records, function (record) {
                    execServer('GetPtJysj', { 'phid': pc.getValue() }, function (res) {
                        if (res.data.length > 0) {
                            fields1.forEach(field => {
                                record.set(field[0], res.data[0][field[1]]);
                            });
                        }
                    });
                    execServer('GetPtJysjUyear', { 'phid': pc.getValue(), 'uyear': jhnd.getValue() }, function (res) {
                        if (res.data.length > 0) {
                            fields2.forEach(field => {
                                record.set(field[0], res.data[0][field[1]]);
                            });
                        }
                    });
                });
                // 设置标志为false，防止再次新增行
                allowAddRowFlag = false;
            } else {
                // 如果不允许新增行，则移除新增的记录
                store.remove(records);
            }
        });
    }
    // 对每个页签调用处理函数，传入相应的参数
    handleAddEvent(d0store, allowAddRow0, [['amt', 'cz']], [['amt_2', 'cz']]);
    handleAddEvent(d1store, allowAddRow1, [['amt', 'sr']], [['amt_9', 'sr']]);
    handleAddEvent(d2store, allowAddRow2, [['amt', 'hk']], [['amt_9', 'hk']]);
    handleAddEvent(d3store, allowAddRow3, [['amt', 'fk']], [['amt_9', 'fk']]);
    // 如果有其他页签，可以按照类似的方式调用 handleAddEvent
}


function GetPtInfo(field, u_fi_org, gfi_ocode) {
    if (field.getValue() !== '' && field.getValue() !== '0' && field.getValue() !== null) {
        execServer('GetPtInfo', { 'phid_pc': field.getValue() }, function (res) {
            if (res.data.length > 0) {
                BatchBindCombox([u_fi_org.setValue(res.data[0].phid_fi_ocode)]);
                BatchBindCombox([gfi_ocode.setValue(res.data[0].phid_fi_ocode)]);
            }
        });
    }
}
{
    //SELECT phid,phid_company,phid_sg_org,approx_contract_fc,user_bzsm,user_cjfs,user_cwzz,user_czlx,user_EASxmbm,user_gtjf,user_lxr,user_lxyj,user_mblrl1,user_ssbm,user_sszg,user_xmfz,user_zjlx,user_zjly,user_zzlb FROM project_table AS pt where phid=@phid
    function updateFormField(container, fieldName, value) {//检查自定义字段是否存在，不存在则跳过
        var field = container.getItem(fieldName);
        if (field) {
            field.setValue(value);
            // 如果需要批量绑定下拉框，则在这里调用 BatchBindCombox 函数
            BatchBindCombox([field]);
        }
    }
    function updateFormFields(container, data) {//需要更新的字段
        if (data.length > 0) {
            updateFormField(container, 'user_bzsm', data[0].user_bzsm);//备注说明U
            updateFormField(container, 'user_cjfs', data[0].user_cjfs);//承接方式U
            updateFormField(container, 'user_cwzz', data[0].user_cwzz);//财务组织U
            updateFormField(container, 'user_czlx', data[0].user_czlx);//建设模式U
            updateFormField(container, 'user_EASxmbm', data[0].user_EASxmbm);//EAS项目编码U
            updateFormField(container, 'user_gtjf', data[0].user_gtjf);//共同甲方U
            updateFormField(container, 'user_lxr', data[0].user_lxr);//立项人U
            updateFormField(container, 'user_lxyj', data[0].user_lxyj);//立项依据U
            updateFormField(container, 'user_mblrl1', data[0].user_mblrl1);//目标利润率U
            updateFormField(container, 'user_ssbm', data[0].user_ssbm);//实施部门U
            updateFormField(container, 'user_sszg', data[0].user_sszg);//实施主管U
            updateFormField(container, 'user_xmfz', data[0].user_xmfz);//项目分组U
            updateFormField(container, 'user_zjlx', data[0].user_zjlx);//资金类型U
            updateFormField(container, 'user_zjly', data[0].user_zjly);//资金来源U
            updateFormField(container, 'user_zzlb', data[0].user_zzlb);//组织类别U
        }
    }
    function getPtInfo(container) {//获取功能扩展及字段来源
        var opt = container.getItem("PhIdOri");
        if (opt.getValue() !== '' && opt.getValue() !== '0' && opt.getValue() !== null) {
            execServer('GetPtInfo', { 'phid': opt.getValue() }, function (res) {
                updateFormFields(container, res.data);
            });
        }
    }
    function AllReady() {
        var adjustmstCmpCfg = Ext.getCmp('adjustmstCmpCfg');//工程建设
        var formProjectTableProjInve = Ext.getCmp('formProjectTableProjInve');//工程投资
        var formProjectTableBusiMana = Ext.getCmp('formProjectTableBusiMana');//企业管理
        if (otype == $Otype.ADD || otype == $Otype.EDIT || otype == $Otype.COPY) {
            if (adjustmstCmpCfg) {//如果是工程建设，则执行
                getPtInfo(adjustmstCmpCfg);
            }
            if (formProjectTableProjInve) {//如果是投资项目则执行
                getPtInfo(formProjectTableProjInve);
            }
            if (formProjectTableBusiMana) {//如果是企业管理，则执行
                getPtInfo(formProjectTableBusiMana);
            }
        }
    }
}
dstore.on('add', async function (store, records, index, eOpts) {
    if (!u_nian.getValue() || !deptid.getValue()) {
        Ext.Msg.alert('提示', '预算年度和预算部门不能为空');
        store.remove(records);
        return;
    }

    for (const record of records) {
        const res90 = await fetchData('getPb90_01', { 'deptid': deptid.getValue(), 'uyear': u_nian.getValue() - 1, 'userhelp': record.get('u_yssjfl') });
        const res132 = await fetchData('GetPb132_01', { 'deptid': deptid.getValue(), 'uyear': u_nian.getValue() - 1, 'ef3_phid': record.get('u_yssjfl') });

        if (res90.data && res90.data.length > 0) {
            record.set('u_snys', res90.data[0].amt_y);
        }
        if (res132.data && res132.data.length > 0) {
            record.set('u_snlj', res132.data[0].amt_y);
        }
    }
});

// Assuming execServer returns a Promise
function fetchData(serverMethod, params) {
    return new Promise((resolve, reject) => {
        execServer(serverMethod, params, resolve);
    });
}

function userSetMustInput(A, B) {
    if (A.getValue() == '295210621000001') {
        B.userSetMustInput(true);// true-必输   false-不必输
    } else {
        B.userSetMustInput(false);// true-必输   false-不必输
    }
}

function AllReady() {
    const mstform = Ext.getCmp('CntM5');
    var CntType = mstform.getItem("CntType");//合同类型
    var user_aqzr = mstform.getItem("user_aqzr");//安全责任人
    if (otype == $Otype.ADD || otype == $Otype.EDIT || otype == $Otype.COPY) {
        userSetMustInput(CntType, user_aqzr);
        CntType.addListener('helpselected', function () { //表头帮助窗口选择后触发
            userSetMustInput(CntType, user_aqzr);
        });
    }
}

function GetTJZQ(mstform, bill_dt, cycleid) {//获取统计周期
    var bill_dt = mstform.getItem("bill_dt");
    var cycleid = mstform.getItem("cycleid");
    execServer('GetTJZQ', { 'BillDt': bill_dt.getValue() }, function (res) {
        if (res.count > 0) {
            cycleid.setValue(res.data[0].phid);
            BatchBindCombox([cycleid])
        }
    });
}
function GetPtCwzz(mstform, pc, u_cwzz) {//获取项目财务组织
    var pc = mstform.getItem('pc');
    var u_cwzz = mstform.getItem("u_cwzz");
    if (pc.getValue() !== '' && pc.getValue() !== '0' && pc.getValue() !== null) {
        execServer('GetPtCwzz', { 'phid_pc': pc.getValue() }, function (res) {
            if (res.count > 0) {
                u_cwzz.setValue(res.data[0].user_cwzz);
                BatchBindCombox([u_cwzz])
            }
        });
    }
}
function getSum(mstform, dstore) {//表体计算 修改后  循环计算前暂停渲染，结束后再开启
    Ext.suspendLayouts();
    var sum = 0;
    for (var i = 0; i < dstore.getCount(); i++) {
        var tax_rate = dstore.getAt(i).get('tax_rate')    //税率
        var qty = dstore.getAt(i).get('qty')    //数量
        var unit_price = dstore.getAt(i).get('unit_price')    //含税单价
        var prc = unit_price / (1 + tax_rate)    //不含税单价
        var tax_price = unit_price * qty   //价税合计
        var amt = tax_price / (1 + tax_rate)    //不含税金额
        var tax_amount = tax_price - amt    //税额
        dstore.getAt(i).set('prc', prc);
        dstore.getAt(i).set('tax_price', tax_price);
        dstore.getAt(i).set('amt', amt);
        dstore.getAt(i).set('tax_amount', tax_amount);
        sum += Ext.Number.from(dstore.getAt(i).get('tax_price'), 0);
        mstform.getItem('tax_price').setValue(sum);
    }
    Ext.resumeLayouts();
}
function allReadyEdit() {//控件设置
    const mstform = Ext.getCmp('p_form0000700142_m');
    const dgrid = Ext.getCmp('p_form0000700142_dgrid');
    const dstore = dgrid.store;


    if (otype == $Otype.ADD || otype == $Otype.EDIT || otype == $Otype.COPY) {
        GetTJZQ(mstform, bill_dt, cycleid);
        GetPtCwzz(mstform, pc, u_cwzz);
        mstform.getItem('pc').addListener('helpselected', function () { //表头帮助窗口选择后触发
            GetPtCwzz(mstform, pc, u_cwzz);
        });

        dgrid.addListener('edit', function (editor, e) {
            getSum(mstform, dstore);

        })

    }
}


function allReadyEdit() {//控件设置
    const mstform = Ext.getCmp('p_form0000700095_m');
    const dgrid = Ext.getCmp('p_form0000700095_dgrid');
    var userhelp_1 = mstform.getItem("userhelp_1");//主文件ID
    var textcol_2 = mstform.getItem("textcol_2");//规格型号
    var msunit = mstform.getItem("msunit");

    if (otype == $Otype.ADD || otype == $Otype.EDIT || otype == $Otype.COPY) {
        mstform.getItem('userhelp_1').addListener('helpselected', function () { //表头帮助窗口选择后触发
            execServer('GetItemdata', { 'phid': userhelp_1.getValue() }, function (res) {
                if (res.count > 0) {
                    textcol_2.setValue(res.data[0].spec);
                    msunit.setValue(res.data[0].phid_msunit);
                    BatchBindCombox([msunit])
                }
            });
        });
    }
}

dgrid.setReadOnlyCol('textcol_1', true);//帮助字段设置  字段名_name  true-只读   false-不只读
dgrid.setMustInputCol('textcol_1', true);// 通用帮助加_name true-必输   false-不必输//	表体控件设为必输	
dgrid.hideColumn('textcol_1', true);// 通用帮助加_name   true-隐藏   false-可见//	表体控件设为隐藏	
dgrid.setMaskCol('textcol_1');//	表体控件设为显示掩码	
dgrid.getColumn('empid1_name').getEditor();//获取表体控件



dgrid.addListener('edit', function (editor, e) {//表体编辑触发
    var record = e.record;
    var data = dgrid.getSelectionModel().getSelection(); //获取当前选中行
    if (e.originalValue == e.value) {//判断原值与新值是否相同
        return;
    }
});
dgrid.on('beforeedit', function (editor, e, eOpts) {// 表体字段编辑事件触发
    const record = e.record;
    if (e.field == '' || e.field == '') {//监听字段变化
    }
});
dgrid.getColumn('pc_name').getEditor().addListener('change', function () {//监听表体某一个字段
    const data = dgrid.getSelectionModel().getSelection();
    const pc = data[0].get('pc');
    callServer('proj', [{ 'phid': pc }], function (res) {
        data[0].set('textcol_1', res.record[0].province + res.record[0].city);
        data[0].set('datetimecol_1', res.record[0].start_date);
        data[0].set('datetimecol_2', res.record[0].end_date);
    });
});//监听单据体编辑事件结束
dgrid.addListener('edit', function (editor, e) {
    dgrid.getColumn('ConNo').getEditor().addListener('helpselected', function () {
        const data = dgrid.getSelectionModel().getSelection();//获取当前选中行
        execServer('GetCnt', { 'phid': data[0].get('PhidCon') }, function (res) {
            if (res.data.length > 0) {
                data[0].set('user_consettleamt', res.data[0].amt5);//割算
                data[0].set('user_consettleamt', res.data[0].amt5);//割算
                data[0].set('user_confinalamt', res.data[0].amt6);//结算
                data[0].set('user_cnt_projbal', res.data[0].amt1);//按合同约定累计应付款额
                data[0].set('user_yfbl', res.data[0].bl2);//按合同约定应付款比例
                data[0].set('user_ljyf', res.data[0].amt1);//累计已付款
                data[0].set('user_fkbl', res.data[0].bl1);//累计已付款比例
                data[0].set('user_qfk', 0);//按合同约定欠付款
            }
        });
    });
});





//表体字段监听
dgrid.getColumn('pc_name').getEditor().addListener('helpselected', function () {
    var data = dgrid.getSelectionModel().getSelection();
    var pc = data[0].get('pc');
    callServer('proj', [{ 'phid': pc }], function (res) {
        data[0].set('textcol_1', res.record[0].province + res.record[0].city);
        data[0].set('datetimecol_1', res.record[0].start_date);
        data[0].set('datetimecol_2', res.record[0].end_date);
    });
});






dgrid.getColumn('u_csdw_name').getEditor().addListener('helpselected', function (record) {     //系统表单表体方案编写表体帮助字段监听
    dgrid.getSelectionModel().getSelection()[0].data.prc = record.data.c_descript;
    dgrid.getView().refresh();
})








// Toolbar.get('deleterow').on('click', function () {
//     //删行时计算
//     var sum = 0
//     for (i = 0; i < dstore2.getCount(); i++) {
//         sum += Ext.Number.from(dstore2.getAt(i).get('user_apply_amt'), 0);

//     }
//     mstform.getItem('ApprovePayAmt').setValue(sum);
// })

// 表体单据引用触发
// dstore.on('datachanged', function (dstore, eOpts) {
//     for (i = 0; i < dstore.getCount(); i++) {
//         var record = dstore.data.items[i];
//     }
// });
//自定义表单单据列表页面初始化	
function allReadyList() {
    //获取当前整体列表
    var dgrid = Ext.getCmp('p_form0000700128_mgrid');
    //获取当前选中行
    var data = dgrid.getSelectionModel().getSelection();
    //获取当前选中行某个字段值
    data[0].get('sgjd');
}


//内嵌查询panel，这个panel不放里面界面会错乱
var queryPanel = Ext.create('Ext.ng3.QueryPanel', {
    toolbar: ngToolbar,
    pageid: "Web:pform0000700128List", //对应内嵌查询业务点标识
    grid: grid,
    queryAutoLoad: false,
    columnsPerRow: 4 //每行4列
});

var ngToolbar = Ext.create('Ext.Gc.Toolbar', {
    region: 'north',
    items: [
        {
            itemId: 'cc',
            text: '我的按钮',
            handler: function () {
                Ext.Msg.alert('提示', '按钮被点击了');
            }
        }
    ]
});


// var Toolbar = Ext.getCmp('ngToolbar');
ngToolbar.insert(8, { itemId: "cjdagd", text: "城建档案归档", width: this.itemWidth, iconCls: "icon-New" });   //指定位置插入按钮
ngToolbar.get('cjdagd').on('click', function () {
    var data = pcTreeGrid.hidden ? grid.getSfelectionModel().getSelection() : pcTreeGrid.getSelectionModel().getSelection();
    if (data.length > 0) {
        var PhId = data[0].get('PhId');
        var CatPhId = data[0].get('CatPhId');
        // var url = C_ROOT + 'PMS/PCM/CntGuarantee/CntGuaranteeEditFir?otype=add&model=1&schemeid=112210713000024&cnttype=5&ocode=331210709000002&Authorization=null';
        var url = C_ROOT + 'SUP/CustomIntegrate/CustomIntegrateEdit?otype=add&hastitle=1&treeorgid=' + CatPhId + '&treeprojid=' + PhId + '&customBusCode=EFORM0000700149&Authorization=ngtokenkey%24PC%241722479482%24747210801000001%24be2bc5fe-942a-4ded-b6fa-05e299827ebb';
        $OpenTab('档案归档', url);
    }
});


dgrid.on('itemdblclick', function (view, record, item, index, e, eOpts) {
    // record 是当前双击行的记录数据
    // var phid = record.get('user_ljjs'); // 假设你要使用 'PhidInnerAcc' 字段作为跳转依据
    // 构建 ClientJsonString 参数
    // 将参数对象转为JSON字符串
    var clientJsonString = JSON.stringify(clientJsonParams);
    // 编码 JSON 字符串以确保 URL 安全
    var encodedClientJsonString = encodeURIComponent(clientJsonString);
    // 跳转逻辑 - 例如，跳转到一个新的页面或视图
    // window.location.href = 'your-target-url?phid=' + phid;
    // 这是在原页面上打开
    // window.location.href = 'http://139.9.135.3:8000/I8/FC/BasicData/UvIAccTypeDet/UvIAccTypeDetList?ClientJsonString=' + encodeURIComponent(clientJsonString);
    // 构建完整的 URL
    // var url = C_ROOT + 'I8/FC/BasicData/UvIAccTypeDet/UvIAccTypeDetList?ClientJsonString=' + encodedClientJsonString;
    var url = C_ROOT + 'I8/FC/BasicData/UvIAccTypeDet/UvIAccTypeDetList';
    console.log(url); // 输出生成的URL以便检查
    $OpenTab('账户资金类型明细表', url);
    // 或者在 ExtJS 应用内跳转到另一个视图
    // Ext.ComponentQuery.query('yourTargetViewSelector')[0].getController().loadRecord(record);
});



{
    //工具栏
    var ngToolbar = Ext.create('Ext.ng.Toolbar', {
        region: 'north',
        rightName: 'UvIAccBal', //权限名称
        ngbuttons: [
            { itemId: "accdet", text: Lang.UvIAccDet || '账户资金明细表', iconCls: "iconfont iconArrowDown", notctr: true },
            { itemId: "acctypedet", text: Lang.UvIAccTypeDet || '账户资金类型明细表', iconCls: "iconfont iconArrowDown", notctr: true },
            { itemId: "accfundtypedet", text: Lang.UvIAccFunTypeDet || '账户资金类型余额明细表', iconCls: "iconfont iconArrowDown", notctr: true },
            { itemId: "accusabledet", text: Lang.UvIAccUsableDet || '在途资金明细表', iconCls: "iconfont iconArrowDown", notctr: true },
            { itemId: "accfundtypeusabledet", text: Lang.UvIAccFundTypeUsableDet || '在途资金类型明细表', iconCls: "iconfont iconArrowDown", notctr: true },
            '->', {
                itemId: "PrintGroup",
                text: "打印",
                langkey: "PrintGroup",
                iconCls: "iconfont iconprint",
                groupitem: true,
                items: [
                    { itemId: "printCurPage", langkey: Lang.printCurPage, text: Lang.printCurPage == undefined ? '打印当前页' : Lang.printCurPage, iconCls: "iconfont iconprint", notctr: true },
                    { itemId: 'printAllPage', langkey: Lang.printAllPage, text: Lang.printAllPage == undefined ? '打印所有页' : Lang.printAllPage, iconCls: "iconfont iconprint", notctr: true }
                ]
            }, 'close'
        ]
    });
    //账户资金明细表
    ngToolbar.get('accdet').on('click', function () {
        goToPage("AccDet");
    });

    //账户资金类型明细表
    ngToolbar.get('acctypedet').on('click', function () {
        goToPage("AccTypeDet");
    });

    //账户资金类型余额明细表
    ngToolbar.get('accfundtypedet').on('click', function () {
        goToPage("AccFundTypeDet");
    });

    //在途资金明细表
    ngToolbar.get('accusabledet').on('click', function () {
        goToPage("AccUsableDet");
    });

    //在途资金类型明细表
    ngToolbar.get('accfundtypeusabledet').on('click', function () {
        goToPage("AccFundTypeUsableDet");
    });
    const upDownPage = {
        AccDet: {
            URL: C_ROOT + "FC/BasicData/UvIAccDet/UvIAccDetList",
            Name: "账户资金明细表",
        },
        AccTypeDet: {
            URL: C_ROOT + "FC/BasicData/UvIAccTypeDet/UvIAccTypeDetList",
            Name: "账户资金类型明细表",
        },
        AccFundTypeDet: {
            URL: C_ROOT + "FC/BasicData/UvIAccFunTypeDet/UvIAccFunTypeDetList",
            Name: "账户资金类型余额明细表",
        },
        AccUsableDet: {
            URL: C_ROOT + "FC/BasicData/UvIAccUsableDet/UvIAccUsableDetList",
            Name: "在途资金明细表",
        },
        AccFundTypeUsableDet: {
            URL: C_ROOT + "FC/BasicData/UvIAccFundTypeUsableDet/UvIAccFundTypeUsableDetList",
            Name: "在途资金类型明细表",
        }
    }
    //报表穿透
    function goToPage(page) {
        var data = grid.getSelectionModel().getSelection();
        if (data.length <= 0) {
            NGMsg.Info("请选择数据！");
            return;
        }
        $OpenTab(upDownPage[page].Name, upDownPage[page].URL + '?phidAcc=' + data[0].get('PhidAcc'));
    }

}


//清空表体
{
    var tabPanel = Ext.getCmp('tabPanel'); // 获取当前所在 tab 页
    var activeTab = tabPanel.getActiveTab(); // 获取当前激活的 tab
    DgridRemove(activeTab.id); // 清空当前激活的 tab 对应的 grid

    function DgridRemove(tabId) {
        var grid = Ext.getCmp(tabId);
        if (grid) {
            grid.getStore().removeAll();
        } else {
            console.log('No grid found with id:', tabId);
        }
    }
}

//自定义表单及系统表单跳转
function allReadyList() {
    window.open(C_ROOT + 'SUP/CustomIntegrate/CustomIntegrateEdit?otype=add&hastitle=1&treeorgid=' + $appinfo.orgID + '&treeprojid=&customBusCode=EFORM0000700142');
    window.close();
}
//系统表单列表打开跳转
function BeforeReady() {
    // 构建包含特定查询参数的新 URL
    var newurl = window.location.origin + '/SUP/CustomPC/CustomPCEdit?otype=add&hastitle=1&issso=1&treeorgid=350000000000002&treeprojid=&customBusCode=EFORM9000000005&Authorization=ngtokenkey%24PC%241723102930%24350000000000587%24ba6926e3-e4a4-4ff4-9127-69e9291ae7a3&AppTitle=%e5%ae%9e%e9%99%85%e6%88%90%e6%9c%ac%e6%8a%a5%e8%a1%a8%ef%bc%88WBS%ef%bc%89'
    // 获取当前 URL
    var url = window.location.href
    // 输出调试信息
    // console.log("Current URL: " + url);
    // console.log("New URL: " + newurl);
    // 检查当前 URL 中是否不包含子字符串 'otype'
    if (url.indexOf('otype') == -1) {//列表界面
        window.location.href = newurl
    }
}
//新增表体弹窗
Ext.getCmp('p_form0000700119_dgrid').getView().addListener('cellclick',function(view, td, cellIndex, record, tr, rowIndex, e, opts){        // 这里是点击单元格时的处理逻辑  
	// 你可以显示一个弹窗来编辑单元格的值  
	console.log(111);

	// 阻止默认的单元格选择行为（如果需要的话）  
	e.stopEvent();  

    // 显示弹窗  
    var editWindow = Ext.create('Ext.window.Window', {  
        title: '编辑单元格',  
        modal: true, // 可以设置为true以阻止用户与页面上的其他元素交互  
        height: 400,  
        width: 500,  
        layout: 'fit',  
        items: [{  
			xtype: 'textarea', // 使用textarea代替textfield  
			itemId: 'editField',  
			value: record.get('u_cwkjfyy'), // 注意：这里直接替换为<br>不会生效  
			// 由于textarea不支持HTML，我们需要保留换行符，让textarea自行处理  
			// 如果确实需要在显示时转换为HTML（比如在其他HTML元素中显示），则应在显示时转换  
			autoScroll: true, // 如果文本很多，可以启用滚动条  
			selectOnFocus: true  
        }],  
        buttons: [{  
            text: '保存',  
            handler: function() {  
                // 从弹窗中获取文本字段的值  
                var newValue = editWindow.down('#editField').rawValue;  
                // 更新原始记录的字段值  
                record.set('u_cwkjfyy', newValue);  
                // 关闭弹窗  
                editWindow.close();  
                // 如果需要，可以调用grid的refresh方法来刷新视图，但通常不需要，因为Ext JS的数据绑定会自动处理  
                // grid.getView().refresh();  
            }  
        }, {  
            text: '取消',  
            handler: function() {  
                editWindow.close();  
            }  
        }]  
    });  

    editWindow.show();  
})

    //input输入框弹窗化
    Ext.get("u_bywc-inputEl").on('dblclick', (e) => {
        Ext.create('Ext.window.Window', {
            title: '请输入上月进展情况！',
            width: 500,
            height: 300,
            layout: 'fit',
            items: [{
                xtype: 'textareafield',
                name: 'value',
                itemId: 'valueField',
                grow: true, // 自动增长高度
                anchor: '100%', // 确保输入框占满整个窗口
                height: 400 // 设置初始高度
            }],
            buttons: [{
                text: '确定',
                handler: function () {
                    var win = this.up('window');
                    var valueField = win.down('#valueField');
                    var inputValue = valueField.getValue();
                    Ext.getCmp("p_form0000700089_m").getItem("u_bywc").setValue(inputValue);
                    win.close();
                }
            }, {
                text: '取消',
                handler: function () {
                    this.up('window').close();
                }
            }]
        }).show();
    });

        //input输入框弹窗化
    Ext.get("u_bywc-inputEl").on('dblclick', (e) => {
    Ext.create('Ext.window.Window', {
        title: '请输入上月进展情况！',
        width: 500,
        height: 300,
        layout: 'fit',
        items: [{
            xtype: 'textareafield',
            name: 'value',
            itemId: 'valueField',
            grow: true, // 自动增长高度
            anchor: '100%', // 确保输入框占满整个窗口
            height: 400 // 设置初始高度
        }],
        buttons: [{
            text: '确定',
            handler: function () {
                var win = this.up('window');
                var valueField = win.down('#valueField');
                var inputValue = valueField.getValue();
                Ext.getCmp("p_form0000700089_m").getItem("u_bywc").setValue(inputValue);
                win.close();
            }
        }, {
            text: '取消',
            handler: function () {
                this.up('window').close();
            }
        }]
    }).show();
}); 
options.useAction("onClick")(() => {
    const selectedRecord = listPage.getSelectedRecord();
    if (!selectedRecord.length) {
        $NG.alert("请先选择数据行");
        return;
    }
    $NG.external.showModal({
        title: '标题',
        content: $NG.createElement('Form', {
            id: 'update_form',
            colspan: 1,
            config: [
                {xtype: 'datepicker', label: '日期', name: 'date'},
                {xtype: 'textfield', label: '数据', name: 'data'}
            ]
        }),
        async onOk(ins) {
            const form = $NG.getCmpApi('update_form');
            const data = form.getValues();
            const phid = selectedRecord[0].phid;
            //更新数据库
            await $NG.execServer('update_data', {a: data.data, b: data.date, phid: phid}, (res) => {
                console.log('res', res)
            })
            ins.destroy();
            //刷新列表
            listPage.refreshList()
        }
    });
}, 'u_ztbg');



if (otype === $Otype.VIEW) {
    toolbar.insert(7, {
      xtype: "button",
      text: "更新计划编制、报审时间",
      iconCls: "icon-Setup",
      handler: function () {
        const window = createWindow();
        window.show();
      },
    });
  
    // 定义模型
    Ext.define("App.model.MyModel", {
      extend: "Ext.data.Model",
      fields: [
        { name: "id", type: "int" },
        { name: "record", type: "string" },
      ],
    });
  
    // 插入“历史修改记录”按钮
    toolbar.insert(8, {
      xtype: "button",
      text: "历史修改记录",
      iconCls: "icon-CheckView",
      handler: function () {
        execServer("select_program_byid", { phid: busid }, (res) => {
          if (res.count > 0) {
            // 创建 Store
            const myStore = Ext.create("Ext.data.Store", {
              model: "App.model.MyModel",
              data: res.data.map((item, index) => ({
                id: index + 1, // 序号从1开始
                record: item.created_at,
              })),
            });
  
            // 创建并显示弹窗
            const gridWindow = Ext.create("Ext.window.Window", {
              title: "历史修改记录",
              width: 500,
              height: 300,
              layout: "fit",
              modal: true, // 模态窗口，避免与其他操作冲突
              items: [
                Ext.create("Ext.grid.Panel", {
                  store: myStore,
                  columns: [
                    { text: "序号", dataIndex: "id", width: 100 },
                    { text: "修改记录", dataIndex: "record", flex: 1 },
                  ],
                  border: false,
                }),
              ],
              buttons: [
                {
                  text: "关闭",
                  handler: function () {
                    gridWindow.close();
                  },
                },
              ],
            });
  
            gridWindow.show();
          } else {
            Ext.Msg.alert("提示", "暂无历史记录！");
          }
        });
      },
    });
  
    // 保存按钮事件
    toolbar.get("save").on("click", function () {
      execServer("insert_program_byid", { phid: busid }, (res) => {
        console.log("Save operation completed.");
      });
    });
  
    // 创建日期选择窗口
    function createWindow() {
      const label = Ext.create("Ext.form.Label", {
        text: "请选择要重置的时间",
        style: "margin-bottom: 10px;",
      });
  
      const datePicker = Ext.create("Ext.picker.Date", {
        format: "Y-m-d",
        width: 220,
      });
  
      const okButton = Ext.create("Ext.button.Button", {
        text: "确定",
        handler: function () {
          const selectedDate = datePicker.getValue();
          const formattedDate = Ext.Date.format(selectedDate, "Y-m-d");
          const currentrows = dgrid.getSelectionModel().getSelection();
          currentrows.forEach((record) => {
            record.set("u_jhbzrq", formattedDate);
          });
          toolbar.get("save").enable();
          window.close();
        },
      });
  
      const cancelButton = Ext.create("Ext.button.Button", {
        text: "取消",
        handler: function () {
          window.close();
        },
      });
  
      const window = Ext.create("Ext.window.Window", {
        title: "请选择日期",
        width: 300,
        height: 315,
        layout: "vbox",
        items: [label, datePicker],
        buttons: [okButton, cancelButton],
        modal: true,
      });
  
      return window;
    }
  }